package oj;

import java.util.Scanner;

public class Day18S {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while (sc.hasNext()){
            String s1=sc.nextLine();
            String s2=sc.nextLine();
            System.out.println(match(s1,s2));
        }
    }

    private static boolean match(String s1, String s2) {
        char[] s11=s1.toCharArray();
        char[] s22=s2.toCharArray();
        int ls1=s11.length;
        int ls2=s22.length;
        boolean[][] arr=new boolean[ls2+1][ls1+1];
        arr[0][0]=true;
            for (int i = 0; i <=ls2 ; i++) {
                for (int j =1 ; j <=ls1 ; j++) {
                    if (s11[j - 1] == '*') {
                        if (i == 0) {
                            arr[i][j] = arr[i][j - 1];
                        } else {
                            if (s22[i - 1] == '.' || (s22[i - 1] >= '0' && s22[i - 1] <= '9') ||
                                    (s22[i - 1] >= 'a' && s22[i - 1] <= 'z') || (s22[i - 1] >= 'A' && s22[i - 1] <= 'Z')) {
                                arr[i][j] = arr[i - 1][j] || arr[i][j - 1];
                            }
                        }
                    } else {
                        if (i > 0 && dfs(s11[j - 1], s22[i - 1])) {
                            arr[i][j] = arr[i - 1][j - 1];
                        }
                    }
                }
            }
            return arr[ls2][ls1];
    }

    private static boolean dfs(char c, char c1) {
        if(c=='?') return true;
        if(c>='a'&&c<='z'){
            c=(char) (c-'a'+'A');
        }
        if(c1>='a'&&c1<='z'){
            c1=(char) (c1-'a'+'A');
        }
        return c==c1;
    }
}
